package com.daohang361.imqq.Asycore;

import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Iterator;

import com.daohang361.imqq.ServerContex.SessionContex;
import com.daohang361.imqq.tool.YYYYmmdd;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-4-5 下午09:45:45 
 */
public class HeartbeatThread implements Runnable{

	@Override
	public void run() {
		while(true){
			
			try {
				Thread.sleep(60000);
				send();
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		
	}
	
	public static void send() throws UnsupportedEncodingException{
		System.out.println("心跳包-------------------------------:"+YYYYmmdd.getNow());
		Collection<QQUser> qqes= SessionContex.getQQList();
		Iterator<QQUser>  it  =  qqes.iterator();  //  获得一个迭代子   
		while(it.hasNext())  {   
			QQUser  qq  =  it.next();  //  得到下一个元素   
			if(qq.isLogin()){
				qq.setCommand(0x58);//设置心跳包
				byte[] send = (qq.getQq() + "").getBytes("UTF-8");
				qq.setSend(send);
			Connector connector=	SessionContex.getConnector(qq.getQq());
			connector.getSession().write(qq);
			}
		}   

	
	
	}

}
